﻿using System.Configuration;
using System.Reflection;
namespace CRMSystemV2.DALFactory
{
    public sealed class DataAccess
    {
        private static readonly string dalName = ConfigurationManager.AppSettings["webDAL"];

        private DataAccess() { }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="typeName">方法名称</param>
        /// <returns></returns>
        public static dynamic CreateInstance(string typeName)
        {           
            typeName = string.Format("{0}.{1}", dalName, typeName);
            string fileName = string.Format("/bin/{0}.dll", dalName);
            Assembly a = Assembly.LoadFrom(System.AppDomain.CurrentDomain.BaseDirectory+ fileName);
            //应用dynamic代替传统反射
            return a.CreateInstance(typeName, false, BindingFlags.CreateInstance, null, null, null, null);
        }
    }
}
